#include <stdio.h>

#define N 6

void swap(int *arr, int i, int j)
{
    int t = arr[i];
    arr[i] = arr[j];
    arr[j] = t;
}

int partition(int *arr, int left, int right)
{
    int i = left, j = right;
    while (i < j)
    {
        while (i < j && arr[j] >= arr[left])
        {
            --j;
        }
        while (i < j && arr[i] <= arr[left])
        {
            ++i;
        }
        if (i < j)
        {
            swap(arr, i, j);
        }
    }
    swap(arr, i, left);
    return i;
}

void quick_sort(int *arr, int left, int right)
{
    if (left >= right)
    {
        return;
    }

    int p = partition(arr, left, right);
    quick_sort(arr, left, p - 1);
    quick_sort(arr, p + 1, right);
}
int main()
{
    int arr[N] = {3, 1, 5, 6, 2, 0};
    quick_sort(arr, 0, N - 1);
    for (int i = 0; i < N; i++)
    {
        printf("%d\n", arr[i]);
    }
    return 0;
}